class Staff < ActiveRecord::Base
     has_many :staff_maintain_relations, dependent: :destroy
  	 has_many :order_maintain_items, through: :staff_maintain_relations
  	 has_many :staff_beauty_relations, dependent: :destroy
  	 has_many :order_beauty_items, through: :staff_beauty_relations

	after_create :gen_code

	def gen_code
	  code = rand(100000).to_s.rjust(6, "0")
  	  update_attributes(code: code)
	end

	def cal_beauty_hour
       add_item = 0
       order_beauty_items.each do |i|
         add_item = add_item + i.beauty_item.working_hour
       end
       add_item
	end

	def cal_maintain_hour
       add_item = 0
       order_maintain_items.each do |i|
         add_item = add_item + i.maintain_item.working_hour
       end
       add_item
	end
end
